﻿using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Zocono.Infrastructure.Common;
using Zocono.WCS.Application.AppEquipmentLayoutManage;
using Zocono.WCS.Infrastructure.ApllicationDto.DtoWcsManage;

namespace Zocono.WCS.WebApi.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class EquipmentLayoutController : ControllerBase
    {
        private readonly ILogUtil _logger;
        private readonly EquipmentLayoutApp _equipmentLayoutApp;
        public EquipmentLayoutController(ILogUtil logger, EquipmentLayoutApp equipmentLayoutApp)
        {
            _logger = logger;
            _equipmentLayoutApp = equipmentLayoutApp;
        }

        #region 设备布局
        [HttpPost]
        public async Task<HeaderResult<long>> AddEquipmentLayoutAsync(EquipmentLayoutInfoDto EquipmentLayoutInfoDto)
        {
            try
            {
                long result = await _equipmentLayoutApp.AddEquipmentLayoutAsync(EquipmentLayoutInfoDto);
                return ApiBase.Success(result, "新增设备布局成功");
            }
            catch (Exception ex)
            {
                _logger.Error(ex.ToString());
                return ApiBase.Error<long>(ex.Message);
            }
        }

        [HttpGet]
        public async Task<HeaderResult<bool>> DeleteEquipmentLayoutAsync(long ID)
        {
            try
            {
                bool result = await _equipmentLayoutApp.DeleteEquipmentLayoutAsync(ID);
                return ApiBase.Success<bool>("删除设备布局成功");
            }
            catch (Exception ex)
            {
                _logger.Error(ex.ToString());
                return ApiBase.Error<bool>(ex.Message);
            }
        }

        [HttpPost]
        public async Task<HeaderResult<bool>> UpdateEquipmentLayoutAsync(EquipmentLayoutInfoDto EquipmentLayoutInfoDto)
        {
            try
            {
                bool result = await _equipmentLayoutApp.UpdateEquipmentLayoutAsync(EquipmentLayoutInfoDto);
                return ApiBase.Success<bool>("修改设备布局成功");
            }
            catch (Exception ex)
            {
                _logger.Error(ex.ToString());
                return ApiBase.Error<bool>(ex.Message);
            }
        }

        [HttpPost]
        public async Task<HeaderResult<List<EquipmentLayoutInfoDto>>> GetAllEquipmentLayoutAsync(QueryEquipmentLayoutInfoDto queryEquipmentLayoutDto)
        {
            try
            {
                var pageList = await _equipmentLayoutApp.GetEquipmentLayoutAsync(queryEquipmentLayoutDto);
                return ApiBase.Info(pageList.Result, pageList.Total, "查询成功");
            }
            catch (Exception ex)
            {
                _logger.Error(ex.ToString());
                return ApiBase.Error<List<EquipmentLayoutInfoDto>>(ex.Message);
            }
        }

        [HttpGet]
        public async Task<HeaderResult<EquipmentLayoutInfoDto>> GetEquipmentLayoutByIDAsync(long ID)
        {
            try
            {
                var result = await _equipmentLayoutApp.GetEquipmentLayoutByIDAsync(ID);
                return ApiBase.Success(result, "获取数据成功");
            }
            catch (Exception ex)
            {
                _logger.Error(ex.ToString());
                return ApiBase.Error<EquipmentLayoutInfoDto>(ex.Message);
            }
        }
        #endregion

        #region 设备布局类型
        [HttpPost]
        public async Task<HeaderResult<long>> AddEquipmentLayoutTypeAsync(EquipmentLayoutTypeInfoDto EquipmentLayoutTypeInfoDto)
        {
            try
            {
                long result = await _equipmentLayoutApp.AddEquipmentLayoutTypeAsync(EquipmentLayoutTypeInfoDto);
                return ApiBase.Success(result, "新增设备布局类型成功");
            }
            catch (Exception ex)
            {
                _logger.Error(ex.ToString());
                return ApiBase.Error<long>(ex.Message);
            }
        }

        [HttpGet]
        public async Task<HeaderResult<bool>> DeleteEquipmentLayoutTypeAsync(long ID)
        {
            try
            {
                bool result = await _equipmentLayoutApp.DeleteEquipmentLayoutTypeAsync(ID);
                return ApiBase.Success<bool>("删除设备布局类型成功");
            }
            catch (Exception ex)
            {
                _logger.Error(ex.ToString());
                return ApiBase.Error<bool>(ex.Message);
            }
        }

        [HttpPost]
        public async Task<HeaderResult<bool>> UpdateEquipmentLayoutTypeAsync(EquipmentLayoutTypeInfoDto EquipmentLayoutTypeInfoDto)
        {
            try
            {
                bool result = await _equipmentLayoutApp.UpdateEquipmentLayoutTypeAsync(EquipmentLayoutTypeInfoDto);
                return ApiBase.Success<bool>("修改设备布局类型成功");
            }
            catch (Exception ex)
            {
                _logger.Error(ex.ToString());
                return ApiBase.Error<bool>(ex.Message);
            }
        }

        [HttpPost]
        public async Task<HeaderResult<List<EquipmentLayoutTypeInfoDto>>> GetAllEquipmentLayoutTypeAsync(QueryEquipmentLayoutTypeInfoDto queryEquipmentLayoutTypeDto)
        {
            try
            {
                var pageList = await _equipmentLayoutApp.GetEquipmentLayoutTypeAsync(queryEquipmentLayoutTypeDto);
                return ApiBase.Info(pageList.Result, pageList.Total, "查询成功");
            }
            catch (Exception ex)
            {
                _logger.Error(ex.ToString());
                return ApiBase.Error<List<EquipmentLayoutTypeInfoDto>>(ex.Message);
            }
        }

        [HttpGet]
        public async Task<HeaderResult<EquipmentLayoutTypeInfoDto>> GetEquipmentLayoutTypeByIDAsync(long ID)
        {
            try
            {
                var result = await _equipmentLayoutApp.GetEquipmentLayoutTypeByIDAsync(ID);
                return ApiBase.Success(result, "获取数据成功");
            }
            catch (Exception ex)
            {
                _logger.Error(ex.ToString());
                return ApiBase.Error<EquipmentLayoutTypeInfoDto>(ex.Message);
            }
        }
        #endregion
    }
}
